package cn.itcast.mapreduce.db.read;

import cn.itcast.mapreduce.db.bean.GoodsBean;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

/**
 * DBInputFormat类用于从SQL表读取数据。底层一行一行读取表中的数据，返回<k,v>键值对。
 * 其中k是LongWritable类型，表中数据的记录行号，从0开始；
 * 其中v是DBWritable类型，表示该行数据对应的对象类型。
 */
public class ReadDBMapper extends Mapper<LongWritable, GoodsBean, LongWritable, Text> {

    //LongWritable outKey = new LongWritable();
    Text outValue = new Text();

    @Override
    protected void map(LongWritable key, GoodsBean value, Context context) throws IOException, InterruptedException {
        //outKey.set(key.get());
        outValue.set(value.toString());

        context.write(key, outValue);
    }
}
